package yu.code.yurpc.listener;

import io.etcd.jetcd.watch.WatchEvent;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import yu.code.yurpc.registry.RegistryServiceCache;

import java.util.Set;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class EtcdRegistryListener implements RegistryListener {
    private RegistryServiceCache registryServiceCache;

    //操作
    @Override
    public void operateCache(Object type) {
        WatchEvent event = (WatchEvent) type;
        switch (event.getEventType()) {
            //key 删除时触发
            case DELETE:
                //清除缓存
                registryServiceCache.clearCache();
                break;
            case PUT: {
            }
            default: {
                break;
            }
        }
    }
}
